package cn.chencaiju.day08;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

public class HashMapTest {
	String[] MONTH= {"一月","二月","三月"};
	String[] MONTH_EN= {"JAN","FEB","MAR"};
	
	public void traverseMap(Map<String, String> map2) {
		Set<Entry<String, String>> entrySet = map2.entrySet();
		for(Entry<String,String> item:entrySet) {
			System.out.println(item.getKey()+"\t"+item.getValue());
		}		
	}
	@Test public void testTraverse() {
		Map<String,String> map=new HashMap<>();
		for(int i=0;i<MONTH.length;i++) {
			map.put(MONTH[i], MONTH_EN[i]);
		}
		traverseMap(map);
	}
	@Test public void testUniqueness() {
		Map<String,String> map=new HashMap<>();
		for(int i=0;i<MONTH.length;i++) {
			map.put(MONTH[i], MONTH_EN[i]);
		}
		System.out.print("原始Map集合：");
		traverseMap(map);
		System.out.print("插入重复键的元素：");
		map.put("三月", "mar");
		traverseMap(map);
		map.put("正月","JAN");
		System.out.println("插入重复元素值，键不重复");
		traverseMap(map);
	}
	
	/*
	 *嵌套集合 
	 */
	@Test public void NestMap() {
		String[] name= {"戴尔","哈弗","盖茨"};
		int[]	mathscores= {88,77,66};
		int[]	englishscores= {100,110,120};
		Map<String,List> nestMap=new HashMap<>();
		for(int i=0;i<mathscores.length;i++) {
			List<Integer> scores = new ArrayList<>();
			scores.add(mathscores[i]);
			scores.add(englishscores[i]);
			nestMap.put(name[i], scores);
		}
		Set<Entry<String, List>> entrySet = nestMap.entrySet();
		for(Entry<String, List> temp:entrySet) {
			System.out.print(temp.getKey()+"\t");
			System.out.println(temp.getValue().toString());
		}
		
	}
	
}
